package common

import (
	"engine/stream/net/http"
	"gitee.com/ameise84/e3dds"
	jsoniter "github.com/json-iterator/go"
)

func ResponseFailed(req e3dds.Request, code uint64, reason ...string) {
	r := map[string]any{
		"code": code,
	}
	if reason != nil && reason[0] != "" {
		r["params"] = reason[0]
	} else {
		r["params"] = "Failed"
	}
	out, _ := jsoniter.Marshal(r)

	req.ResponseMsg(http.HttpReqFailed, out)
}

func ResponseSuccess(req e3dds.Request, jsonData ...any) {
	r := map[string]any{
		"code":   0,
		"params": "Success",
	}
	if jsonData != nil && jsonData[0] != "" {
		r["data"] = jsonData[0]
	}
	out, _ := jsoniter.Marshal(r)
	req.ResponseMsg(http.HttpReqSuccess, out)
}
